package com.example.mountainwalker.mapper;

import com.example.mountainwalker.entity.RegionInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RegionMapper {
    @Select("SELECT * FROM mw.region")
    List<RegionInfo> getAllRegions();

    @Select("SELECT * FROM mw.region WHERE RegionID = #{regionId}")
    RegionInfo getRegionById(@Param("regionId") Integer regionId);

    @Insert("INSERT INTO mw.region(Province, City) VALUES(#{province}, #{city})")
    @Options(useGeneratedKeys = true, keyProperty = "regionID")
    int insertRegion(RegionInfo regionInfo);

    @Update("UPDATE mw.region SET Province = #{province}, City = #{city} WHERE RegionID = #{regionID}")
    int updateRegion(RegionInfo regionInfo);

    @Delete("DELETE FROM mw.region WHERE RegionID = #{regionId}")
    int deleteRegion(@Param("regionId") Integer regionId);

    @Select("SELECT * FROM mw.region WHERE Province LIKE CONCAT('%', #{province}, '%')")
    List<RegionInfo> searchByProvince(@Param("province") String province);

    @Select("SELECT * FROM mw.region WHERE City LIKE CONCAT('%', #{city}, '%')")
    List<RegionInfo> searchByCity(@Param("city") String city);
}